package com.itheima.d6_singleInstance;

/**
 * 懒汉单例：使用时再赋值
 */
public class Wife2 {
    private String name;

    //2. 提供一个当前类型的类变量
    private static Wife2 wife2;//默认null


    //1. 私有化构造器
    private Wife2() {
        name = "古力娜扎";
    }


    //3. 提供一个类方法返回单例对象
    public static Wife2 getInstance() {
        if (wife2==null) {
            //第一次调用方法时为null，创建一个对象
            wife2 = new Wife2();
        }

        return wife2;
    }




    public void show() {
        System.out.println("我老婆是" + name);
    }

}
